package com.turnengine.client.local.action.bean;

import com.javabi.common.io.data.IDataReader;
import com.javabi.common.io.data.IDataWriter;
import java.io.IOException;

/**
 * The Action Serializer.
 */
public class ActionSerializer implements IActionSerializer {

	@Override
	public IAction readObject(IDataReader reader) throws IOException {

		// Read fields
		int actionId = reader.readInt();
		int turns = reader.readInt();
		int limit = reader.readInt();

		// Create object
		IAction object = new Action();
		object.setActionId(actionId);
		object.setTurns(turns);
		object.setLimit(limit);
		return object;
	}

	public void writeObject(IDataWriter writer, IAction object) throws IOException {

		// Get fields
		int actionId = object.getActionId();
		int turns = object.getTurns();
		int limit = object.getLimit();

		// Write fields
		writer.writeInt(actionId);
		writer.writeInt(turns);
		writer.writeInt(limit);
	}
}
